#!/usr/bin/perl
# index.cgi in emailalert
require './emailalert-lib.pl';
&header($text{'index_title'},undef,"index",undef,0);
&ReadParse();
my ($status,$hqstat,$sender,$passwd,$receiver,$smtp,$crit,$info,$warning);
my %data=&get_conf_data();
if(%in){
	my $changed = 0;
	$status   = $in{'status'};
        $hqstat = $in{'hqstat'};
	$passwd   = $in{'passwd'};
	$sender   = $in{'sender'};
	$receiver = $in{'receiver'};
	$smtp     = $in{'smtp'};
	$crit     = $in{'crit'} ? 'yes':'no';
	$info     = $in{'info'} ? 'yes':'no';
	$warning  = $in{'warning'} ? 'yes':'no';
	$changed  = 1 if($status   ne $data{'status'});
        $changed  = 1 if($hqstat  ne $data{'hqstat'});
	$changed  = 1 if($sender   ne $data{'sender'});
	$changed  = 1 if($passwd   ne $data{'passwd'});
	$changed  = 1 if($receiver ne $data{'receiver'});
	$changed  = 1 if($smtp     ne $data{'smtp'});
	$changed  = 1 if($crit     ne $data{'crit'});
	$changed  = 1 if($info     ne $data{'info'});
	$changed  = 1 if($warning  ne $data{'warning'});
	if($changed){ 
		$data{'status'}		= $status;
                $data{'hqstat'}	= $hqstat;
		$data{'sender'}		= $sender;
		$data{'passwd'}		= $passwd;
		$data{'receiver'}	= $receiver;
		$data{'smtp'}		= $smtp;
		$data{'crit'}		= $crit;
		$data{'info'}		= $info;
		$data{'warning'}	= $warning;
		&save_conf_data(\%data) 
	}
}else{
	$status   = $data{'status'};
        $hqstat  = $data{'hqstat'};
	$sender   = $data{'sender'};
	$passwd   = $data{'passwd'};
	$receiver = $data{'receiver'};
	$smtp     = $data{'smtp'};
	$crit     = $data{'crit'};
	$info     = $data{'info'};
	$warning  = $data{'warning'};
}


if($status eq "enable")  { 
	$en_checked='checked';
	$dis_checked='';
} else {
	$dis_checked='checked';
	$en_checked='';
}

if($hqstat eq "enable")  {
        $en_checkedb='checked';
        $dis_checkedb='';
} else {
        $dis_checkedb='checked';
        $en_checkedb='';
}

$crit_checked= ($crit eq 'yes') ? 'checked':''; 
$info_checked= ($info eq 'yes') ? 'checked':''; 
$warning_checked= ($warning eq 'yes') ? 'checked':''; 


print <<EOF;
<form name=set method=post action=index.cgi ><p>

<table class=mode1 width=75% border=0>
<tr><td>$text{'receiver'}:</td>
    <td><input class=text type=text size=35 name=receiver value=$receiver></td>
</tr>
<tr><td>$text{'sender'}:</td>
    <td><input class=text type=text size=35 name=sender value=$sender></td>
</tr>
<tr><td>$text{'pswd'}:</td>
    <td><input class=text type=password size=35 name=passwd value=$passwd></td>
</tr>
<tr><td>$text{'smtp'}:</td>
    <td><input class=text type=text size=35 name=smtp value=$smtp></td>
</tr>
<tr>
  <td valign=top>$text{'content_title'}:</td>
  <td>
  <p><textarea rows=5 name="content" cols=30 >$text{'content'}</textarea></p>
  </td>
</tr>
<tr><td>$text{'alert'}:</td>
    <td><input type=radio name=status value=disable $dis_checked >
	$text{'disable'}
        <input type=radio name=status value=enable  $en_checked  >
	$text{'enable'}
    </td>
</tr>

<tr><td>$text{'hanqin'}:</td>
    <td><input type=radio name=hqstat value=disable $dis_checkedb >
        $text{'disable'}
        <input type=radio name=hqstat value=enable  $en_checkedb  >
        $text{'enable'}
    </td>
</tr>

<tr><td>$text{'send'}:</td>
    <td><input type='checkbox' name='crit' value='yes' $crit_checked >
	$text{'crit'} 
        <input type='checkbox' name='warning' value='yes' $warning_checked >
	$text{'warning'}
        <input type='checkbox' name='info' value='yes' $info_checked >
	$text{'info'}
    </td>
</tr>
</table>

<table>
<tr>
<td>
   <input class=button1 type=submit  value=$text{'submit'}>
</td>
</form>
<td>
   <input class=button type=button  value=$text{'test'} 
    onclick='window.open("test.cgi?smtp="+document.set.smtp.value+
"&receiver="+document.set.receiver.value+ 
"&sender="+document.set.sender.value+ 
"&passwd="+document.set.passwd.value+ 
"&content="+document.set.content.value, 
"",
"toolbar=no,menubar=no,scrollbars=yes,width=400,height=200")
'>
</td>
</tr>
</table>


EOF
&footer("/",$text{'index'});
